//
//  BWBaseNavController.swift
//  weibo
//
//  Created by libowen on 16/5/20.
//  Copyright © 2016年 libowen. All rights reserved.
//

import UIKit

class BWBaseNavController: UINavigationController,UIGestureRecognizerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        var backtitle = "返回"
        if childViewControllers.count > 0 {
            if childViewControllers.count == 1 {
                backtitle = childViewControllers.first?.title ?? "返回"
            }
            let back = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backtitle, target: self, action: "popToFrontVC")
            
            viewController.navigationItem.leftBarButtonItem = back
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popToFrontVC() {
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count > 1
    }
}





















